<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.search" placeholder="鉴赏ID"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getUser">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <template>
      <el-table :data="users" highlight-current-row v-loading="loading" style="text-align: center;">
        <el-table-column header-align="center"  prop="id" label="鉴赏ID"  width="120">
        </el-table-column>
        <el-table-column header-align="center" prop="username" label="送鉴用户">
        </el-table-column>
        <el-table-column header-align="center" prop="name" label="品类" width="300" >
        </el-table-column>
        <el-table-column header-align="center" prop="realName" label="鉴定专家" width="200" >
        </el-table-column>
        <el-table-column header-align="center" prop="createTime" label="发布时间" width="200" >
        </el-table-column>
         <el-table-column header-align="center" prop="replyTime" label="完成时间" width="200" >
        </el-table-column>
        <el-table-column header-align="center" label="操作" width="300">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">查看详情</el-button>
          <el-button v-if='!scope.row.actType' @click='setFreebtn(scope.$index, scope.row)' size="small">设为免费</el-button>
          <el-button type="warning" v-if='scope.row.actType' size="small">已免费</el-button>
        </template>
      </el-table-column>
      </el-table>
    </template>
      <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="num" :total="total" style="float:right;">
      </el-pagination>
      <div class="all">总计<span class="total">{{total}}</span>条记录</div>
    </el-col>
    <!-- 设置免费提示 -->
    <el-dialog
  title="设置免费提示"
  :visible.sync="centerDialogVisible"
  width="30%"
  center>
  <span>是否确认将此条鉴赏设置为免费</span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="setFree">确 定</el-button>
  </span>
</el-dialog>
  </section>
</template>
<script>
  import util from '../../common/js/util'
  import { sendData,cutString,sendDataPost } from "../../api/api";
  export default {
    data() {
      return {
        filters: {
          search: ''
        },
        loading: false,
        users: [
        ],
        total: 0,
        page: 1,
        num:20,
        centerDialogVisible:false,
        taskId:""
      }
    },
    methods: {
      //获取所有用户已完成鉴赏列表
      getUser: function () {
        let para = this.filters.search;
          if (para!==""&&isNaN(para)) {
             this.$message({
              message: "请输入正确的鉴赏ID",
              type: "error"
            });
          return
          }
        let page=JSON.parse(this.page);
        let params=sendData({url: "appraisal/list",msg: {search:para,pgNo:page,num:this.num,order:2,status: 1}})
        this.loading = true;
        this.$http.get(params.baseURL,{params:params.params}).then(res=>{
          var res=cutString(res.bodyText)
          this.total=res.msg.total
          this.users = res.msg.taskStatusRsps
          res.msg.taskStatusRsps.map(function(v,i){
            v.createTime=v.createTime.slice(0,19)
            v.replyTime= v.replyTime.slice(0,19)
          })
          this.loading = false;
          console.log(res)
        })
      },
      // 分页请求
      handleCurrentChange(val) {
        console.log(val)
        this.page = val;
        this.getUser();
      },
      // 设置免费弹窗，并获取ID
      setFreebtn(index,row){
        this.centerDialogVisible=true,
        this.taskId=row.id
        console.log(row.id)
      },
      // 设置免费
      setFree(){
        let params=sendDataPost({url: "appraisal/setActType",msg: {taskId:this.taskId,actType:"20180313"}})
        let data=JSON.stringify(params.params)
        this.$http.post(params.baseURL,data).then(res=>{
          this.centerDialogVisible=false
          this.getUser()
        })
      },
      //查看详情界面
      handleEdit: function (index, row) {
        //  this.$router.push({  
        //     path: '/appreciateDetails',   
        //     name: '鉴赏详情',  
        //     params: {   
        //         id: row.id, 
        //         category:row.name,
        //         expert:row.realName  
        //     }   
        // })
        window.open("./static/preview/appreciateDetails.html?id="+row.id+'&category='+row.name+"&expert="+row.realName)
      },

    },
    watch:{
       'filters.search':function(){
        if (this.filters.search=='') {
          this.getUser();
        }
       }, 
  },
    mounted() {
      this.getUser();
    }
  };

</script>

<style scoped>
.all{
  font-size: 16px;
  line-height: 32px;
  color: #666
}
.total{
    padding:0 5px;
    color: #52BAE9;
  }
</style>